﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QxFramework.Core;
using QxFramework.Utilities;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public enum Procedure
{
    StartGame,
    MainProcedure,
}

public class UIManager_New : MonoSingleton<UIManager_New>
{
    public Canvas C_Start_UI;
    public Canvas C_JobChoose_UI;
    public Canvas C_SkillChoose_UI;
    public Canvas C_Main_UI;
    public EntityBase Player;
    // Use this for initialization
    public float playerhealth = 100.0f;
    public float playerpower = 100.0f;
    public float _taskNumber = 0f;
    public float _level = 0f;
    public float _wave = 0f;
    public Text taskNumber_text;
    public Text skillTime_text;
    public Text level_text;
    public Text wave_text;
    public Image currentHealth;
    public Image currentPower;
    public Image currentExp;
    public Image skillTest;
    private bool beginCD = false;
    public void Start()
    {
        DontDestroyOnLoad(this);
    }
    public void OnClick_JobChoose()//触发按钮进入职业选择
    {
        C_Start_UI.gameObject.SetActive(false);
        C_JobChoose_UI.gameObject.SetActive(true);
    }

    public void OnClick_GameScene()//触发按钮切换至主场景
    {
        SceneManager.LoadScene(sceneName: "Main");//Main为我们要切换到的场景
        C_JobChoose_UI.gameObject.SetActive(false);
        ProcedureManager_New.Instance.ChangeProcedure(ProcedureManager_New.Instance.mainProcedure);
    }

    public void OnClick_SkillChoose()//触发按钮完成天赋选择并退出
    {
        C_SkillChoose_UI.gameObject.SetActive(false);
    }
    public void Quit()//退出游戏
    {
        UnityEditor.EditorApplication.isPlaying = false;//*将状态设置false才能退出游戏*
        Application.Quit();

    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Alpha1))//测试直接进入游戏主界面场景
        {
            SceneManager.LoadScene(sceneName: "Main");
        }
        else if (Input.GetKeyUp(KeyCode.Alpha2))//测试直接返回开始场景
        {
            SceneManager.LoadScene(sceneName: "StartGame");
        }
        else if (Input.GetKeyDown(KeyCode.Alpha0))//测试天赋选择UI
        {
            if (ProcedureManager_New.Instance.currentProcedure == ProcedureManager_New.Instance.mainProcedure)
            {
                C_SkillChoose_UI.gameObject.SetActive(true);
            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha9))//测试技能任务进度UI
        {
            if (ProcedureManager_New.Instance.currentProcedure == ProcedureManager_New.Instance.mainProcedure)
            {
                _taskNumber += 10;
                UpdateTaskProgress(_taskNumber);

            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha8))//测试血量蓝量UI
        {
            if (ProcedureManager_New.Instance.currentProcedure == ProcedureManager_New.Instance.mainProcedure)
            {
                playerhealth -= 10;
                playerpower -= 18;
                currentHealth.fillAmount = playerhealth / 100.0f;
                currentPower.fillAmount = playerpower / 100.0f;
          
            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha7))//测试波次UI
        {
            if (ProcedureManager_New.Instance.currentProcedure == ProcedureManager_New.Instance.mainProcedure)
            {
                _wave +=10;
                UpdateWave(_wave);

            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha6))//测试技能UI
        {
            if (ProcedureManager_New.Instance.currentProcedure == ProcedureManager_New.Instance.mainProcedure && beginCD == false)
            {
                beginCD = true;
                skillTest.fillAmount = 1.0f;
            }
        }
        else if (Input.GetKeyDown(KeyCode.Alpha5))//测试等级UI
        {
            if (ProcedureManager_New.Instance.currentProcedure == ProcedureManager_New.Instance.mainProcedure)
            {
                _level += 10;
                UpdateLevel(_level);

            }
        }

        if (beginCD == true)
        {
            skillTest.fillAmount -= Time.deltaTime/ 3.0f;
            skillTime_text.text = (skillTest.fillAmount * 3.0f).ToString("0.00");
            if (skillTest.fillAmount == 0)
            {
                beginCD = false;
                skillTime_text.text = "";
                skillTest.fillAmount = 1.0f;
            }
        }
    }
    public void UpdateHp(EntityBase player)
    // UI读取当前血量量状态并显示
    {
        currentHealth.fillAmount = player.parameter.HealthData.currentHealth / player.parameter.HealthData.maxHealth;
    }
    public void UpdateMp(EntityBase player)
    // UI读取当前蓝量状态并显示
    {
        currentPower.fillAmount = player.parameter.ManaData.CurrentMana / player.parameter.ManaData.maxMana;
    }
    public void UpdateExp(EntityBase player)
    // UI读取当前经验值状态并显示
    {
        //currentPower.fillAmount = player.parameter.HealthData.currentHealth / player.parameter.HealthData.maxHealth;
    }
    public void UpdateAllData(EntityBase player)
    // UI读取当前血量，蓝量及经验值状态并显示
    {
        UpdateHp(player);
        UpdateMp(player);
        UpdateExp(player);
    
    }
    public void UpdateSkillCoolDown(EntityBase player, Skills skill)
    // UI读取当前技能冷却状态并显示
    {
        if (player.skillList[skill].isColddown == true)
        {
            skillTest.fillAmount = player.skillList[skill].colddownTimer / player.skillList[skill].colddownTime;
            skillTime_text.text = (skillTest.fillAmount * player.skillList[skill].colddownTime).ToString("0.00");

        }
        else
        {
            skillTime_text.text = "";
            skillTest.fillAmount = 0f;
        }
    }
    public void UpdateLevel(float level)//等级显示UI
    {
        level_text.text = level.ToString();
    }
    public void UpdateTaskProgress(float taskNumber)//任务进度显示UI
    {
        taskNumber_text.text = taskNumber.ToString();
    }
    public void UpdateWave(float wave)//波次显示UI
    {
        wave_text.text = wave.ToString();
    }

}
